<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no' name='viewport'/>
    <title>毕业设计选题系统</title>
    <link rel="stylesheet" type="text/css" th:href="@{/webjars/bootstrap/3.3.7/css/bootstrap.min.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/asserts/css/demo.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/asserts/css/ready.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/css/element-ui.css}">

    <style>
        th,td {
            text-align: center
        }
        a:hover{text-decoration:none}
    </style>
</head>
<body>
<div class="wrapper" id="app">
    <div th:replace="student/public-student-index :: header"></div>

    <div th:replace="student/public-student-index :: left"></div>

    <div class="main-panel">
        <div class="content">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">课题名称：
                        <span id="project_Name" style="color: #dd6161;font-size: 13pt" th:text="${projectName}"></span>
                        <span id="project_id" style="color: #dd6161; display: none" th:text="${project_id}"></span>
                    </h3>
                </div>
                <div class="panel-body">
                    请下载该课题附件查看相关需求：
                    <el-link :underline="false" style="font-weight: bold;">
                        <a th:href="@{/static/file_download(project_Name=${projectName})}">
                            下载附件
                        </a>
                    </el-link>

                    <!--<el-button type="success" plain style="float: right;">成功按钮</el-button>-->

                    <div  style="float: right">
                        <span th:if="${selectFlag} eq 1">
                            <el-button id="xb" @click="tips" th:value="${flag}">无法选报</el-button>
                        </span>
                        <span th:unless="${selectFlag} eq 1">
                            <span th:if="${XZproject} ne null">
                            <span th:if="${XZproject} eq ${projectName}">
                                <el-button id="xb" @click="tips" th:value="${flag}">
                                    <span th:if="${flag} eq 0">选报</span>
                                    <span th:if="${flag} eq 1">取消选报</span>
                                    <span th:if="${flag} eq 2">选报</span>
                                    <span th:if="${flag} eq 3">无法选报</span>
                                </el-button>
                            </span>
                            <span th:unless="${XZproject} eq ${projectName}">
                                <el-button id="xb" @click="tips" value="4">
                                    无法选报
                                </el-button>
                            </span>
                        </span>
                        <span th:unless="${XZproject} ne null">
                            <el-button id="xb" @click="tips" th:value="${flag}">
                                <span th:if="${flag} eq 0">选报</span>
                                <span th:if="${flag} eq 1">取消选报</span>
                                <span th:if="${flag} eq 2">选报</span>
                                <span th:if="${flag} eq 3">无法选报</span>
                            </el-button>
                        </span>
                        </span>

                    </div>
                </div>
            </div>
            <table class="table table-bordered table-hover" style="background-color:white;">

                <tr class="danger">
                    <th>序号</th>
                    <th>班级</th>
                    <th>学号</th>
                    <th>姓名</th>
                    <th>课题</th>
                    <th>状态</th>
                </tr>

                <tr th:each="list,iterStar : ${topicstos}">
                    <td th:text="${iterStar.count}">${status.count}</td>
                    <td th:text="${list.className}">${project.className}</td>
                    <td th:text="${list.stuNum}">${project.stuNum}</td>
                    <td th:text="${list.name}">${project.name}</td>
                    <td th:text="${projectName}">${projectName}</td>
                    <td th:if="${list.stuSelectFlag==0}">未选题</td>
                    <td th:if="${list.stuSelectFlag==1}">选题待审核</td>
                    <td th:if="${list.stuSelectFlag==2}">选题未通过</td>
                    <td th:if="${list.stuSelectFlag==3}">选题通过</td>
                </tr>
            </table>
        </div>
    </div>



</div>


</body>
<script type="text/javascript" th:src="@{/webjars/jquery/1.9.1/jquery.js}"></script>
<script type="text/javascript" th:src="@{/webjars/bootstrap/3.3.7/js/bootstrap.min.js}"></script>
<script type="text/javascript" th:src="@{/asserts/js/ready.min.js}"></script>
<!--<script type="text/javascript" th:src="@{/js/topics.js}"></script>-->
<script type="text/javascript" th:src="@{/js/Vue.js}"></script>
<script type="text/javascript" th:src="@{/js/element-ui.js}"></script>

<script th:inline="javascript" type="text/javascript">

    var basePath= /*[[${#httpServletRequest.getContextPath()}]]*/'ContextPath' ;


    var app = new Vue({
        el:"#app",
        data(){
            return{
                show:false
            }
        },
        methods: {
            tips(){
                console.log([[${selectFlag}]])
                xb = [[${selectFlag}]]
                if(xb==1){
                    alert("此课题已满")
                }else{
                    console.log($('#xb').val());
                    if ($('#xb').val() == "0" || $('#xb').val() == "2") {
                        var project_id = $("#project_id").html();
                        $.ajax({
                                type: 'GET',
                                url: basePath+'/student/enroll',
                                dataType: 'json', //表示返回值的数据类型
                                contentType: 'application/json;charset=UTF-8', //内容类型
                                data: {"project_id": project_id},
                                success: function (res) {
                                    if (res == 200) {
                                        alert("选报成功，请耐心等待导师回复！");
                                        $('#xb').html("取消选报");
                                        window.location.reload();
                                    }
                                    if (res == 201) {
                                        alert("选报失败！")
                                    }
                                }
                            }
                        );
                    }
                    else if ($('#xb').val() == "1") {
                        var project_id = $("#project_id").html();
                        $.ajax({
                                type: 'GET',//DELETE
                                url: basePath+'/student/cancel',
                                dataType: 'json', //表示返回值的数据类型
                                contentType: 'application/json;charset=UTF-8', //内容类型
                                data: {"project_id": project_id},
                                success: function (res) {
                                    if (res == 200) {
                                        alert("取消成功！");
                                        $('#xb').html("选报");
                                        window.location.reload();//偷懒做的
                                    }
                                    if (res == 203) {
                                        alert("取消选报失败！");
                                    }
                                }
                            }
                        );
                    } else if ($('#xb').val() == "3") {
                        alert("您以选题成功，如需重选请联系该课题导师，取消您的选择");
                    }else {
                        alert("你以选择其他课题，如想选择本课题，请先取消已报名课题");
                    }
                }

            }
        }

    })

</script>

</html>
